<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>修改员工页面</h1>
<form action="">
    <input type="text" v-model="emp.id" readonly name="id">
    <input type="text" v-model="emp.name" name="name">
    <input type="text" v-model="emp.sal" name="sal">
    <input type="text" v-model="emp.job" name="job">
    <input type="button" value="修改" @click="update()">
</form>
<!--引入vue-->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<!--引入axios框架-->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
    let vm =new Vue({
        el:"form",
        data:{
            emp:{}
        },
        created:function () {
            //得到地址栏中的id
            let id = location.search.split("=")[1];
            //发出异步请求
            axios.get("/selectbyid?id="+id).then(function (response) {
                //把服务器返回的员工对象
                vm.emp = response.data;
            })
        },
        methods:{
            update:function () {
                let data = new FormData(document.querySelector("form"));
                axios.post("/update",data).then(function () {
                    alert("修改完成!")
                    location.href="/list.html";
                })
            }
        }
    })
</script>
</body>
</html>